//////////////////////////////////////////////////////////////////////////
#include <RocketLua/RocketLua.hpp>
#include <cmath>



using namespace Rocket::Core::Lua;

//////////////////////////////////////////////////////////////////////////

Vector2i::Vector2i()
:	mX( 0 )
,	mY( 0 )
{
}


Vector2i::Vector2i( int32_t x, int32_t y )
:	mX( x )
,	mY( y )
{
}


int32_t Vector2i::X() const
{
	return mX;
}


void Vector2i::X( int32_t x )
{
	mX = x;
}


int32_t Vector2i::Y() const
{
	return mY;
}


void Vector2i::Y( int32_t y )
{
	mY = y;
}


Vector2i& Vector2i::Set( int32_t x, int32_t y )
{
	mX	=	x;
	mY	=	y;
	return *this;
}


bool Vector2i::operator == ( const Vector2i& rhs ) const
{
	return mX==rhs.mX && mY==rhs.mY;
}


Vector2i Vector2i::Negate() const
{
	return Vector2i( -mX, -mY );
}

Vector2i Vector2i::operator +( const Vector2i& rhs ) const
{
	return Vector2i( mX+rhs.mX, mY+rhs.mY );
}


Vector2i Vector2i::operator -( const Vector2i& rhs ) const
{
	return Vector2i( mX-rhs.mX, mY-rhs.mY );
}


Vector2i Vector2i::operator *( int32_t rhs ) const
{
	return Vector2i( mX*rhs, mY*rhs );
}


Vector2i Vector2i::operator /( int32_t rhs ) const
{
	return Vector2i( mX/rhs, mY/rhs );
}


float Vector2i::Magnitude() const
{
	return std::sqrt( float( mX*mX + mY*mY ) );
}


void Vector2i::Register( lua_State* state )
{
	luabridge::getGlobalNamespace( state )
		.beginClass< Vector2i >( "Vector2i" )
		.addConstructor< void (*)( void ) >()
		.addProperty( "x", &Vector2i::X, &Vector2i::X )
		.addProperty( "y", &Vector2i::Y, &Vector2i::Y )
		.addFunction( "Set", &Vector2i::Set )
		.addFunction( "__eq", &Vector2i::operator == )
		.addFunction( "__unm", &Vector2i::Negate )
		.addFunction( "__add", &Vector2i::operator + )
		.addFunction( "__sub", &Vector2i::operator - )
		.addFunction( "__mul", &Vector2i::operator * )
		.addFunction( "__div", &Vector2i::operator / )
		.addFunction( "Magnitude", &Vector2i::Magnitude )
		.endClass();
}
